Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
"axios.defaults.headers.common['Content-Type'] = 'application/json'" but axios.post still is "application/x-www-form-urlencoded"

I set axios common header Content-Type = application/json by below code:

axios.defaults.headers.common['Content-Type'] = 'application/json';

But when I tried to use axios.post('apiurl', json), browser Content-Type still is application/x-www-form-urlencoded

enter image description here

I tried to use axios.post('Get_Office_PO_NO_Data', json, { headers: { 'content-type': 'application/json' } }) and axios can request application/json content type

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Per the documentation, you want post, not common:

axios.defaults.headers.post['Content-Type'] = 'application/json';
// −−−−−−−−−−−−−−−−−−−−^^^^

Which makes sense; other request types (GET, DELETE, etc.) don't have any request body to apply the content type to. (PUT and PATCH do, but I guess they figured it was unlikely you'd want to set the same default content type for POST and PUT, or it was just the whim of the developer.)

(Alternatively you might consider creating an instance with your defaults via axios.create, and then using the instance. Changing global defaults always makes me a bit uneasy. :-) )

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda